//
//  NormalLineChartDataSet.swift
//  TimeBoat
//
//  Created by bo wang on 2022/8/26.
//  Copyright © 2022 Time Boat. All rights reserved.
//

import UIKit
import Charts

class NormalLineChartDataSet: LineChartDataSet {
    override init(entries: [ChartDataEntry], label: String) {
        super.init(entries: entries, label: label)
        setupDataSet()
    }
    
    required init() {
        super.init()
        setupDataSet()
    }
    
    func setupDataSet() {
        
//        set.visible
        
        // 线的设置
    
//        set.isDrawLineWithGradientEnabled = false
//        set.gradientPositions
//        set.lineDashPhase
//        set.lineDashLengths
//        set.lineCapType = .butt
        lineWidth = 4
        cubicIntensity = 0.2
        mode = .cubicBezier
        
        // 数据的点
//        circleRadius = 2
//        circleHoleRadius = 1
//        setCircleColor(.white)
        drawCirclesEnabled = false
//        circleHoleColor = HEX(0xEAAD3C)
//        drawCircleHoleEnabled = true
//        set.drawIconsEnabled = true
//        set.iconsOffset
        
        // 填充
//        set.fillFormatter
//        set.fillColor
//        set.fill
//        set.fillAlpha
        drawFilledEnabled = true
        let gradientColors = [
            UIColor(hex: 0xFF8800)!.cgColor,
            UIColor.white.cgColor
        ]
        let gradient = CGGradient(colorsSpace: nil, colors: gradientColors as CFArray, locations: nil)!
        fill = LinearGradientFill(gradient: gradient, angle: -90)
        
        // 指示器
//        set.drawHorizontalHighlightIndicatorEnabled
//        set.drawVerticalHighlightIndicatorEnabled
//        set.setDrawHighlightIndicators(false)
        
        // 高亮
//        set.highlightColor
//        set.highlightLineWidth
//        set.highlightLineDashPhase
//        set.highlightLineDashLengths
//        set.highlightEnabled
        
        // 其他
        setColor(HEX(0xFF5E32)!)
//        set.colors
//        set.valueColors
        axisDependency = .left
//        set.valueTextColor
//        set.valueFont
//        set.valueLabelAngle
//        set.valueFormatter
        drawValuesEnabled = false
        
        // form
        form = .none
//        set.formSize
//        set.formLineWidth
//        set.formLineDashPhase
//        set.formLineDashLengths
    }
    
    override func entryForXValue(_ xValue: Double,
                                 closestToY yValue: Double,
                                 rounding: ChartDataSetRounding)
    -> ChartDataEntry? {
        let fixedValue = Swift.min(Swift.max(xValue, xMin), xMax)
        return super.entryForXValue(fixedValue, closestToY: yValue, rounding: rounding)
    }
    
    func setupShowCircleDot() {
        circleRadius = 4
        circleHoleRadius = 2
        setCircleColor(HEX(0xEAAD3C)!)
        drawCirclesEnabled = true
        circleHoleColor = .white
        drawCircleHoleEnabled = true
    }
}
